package com.vcredit.creditcat.framework.util;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
/**
 * 图片工具
 *
 */
public class ImageUtil {
	private static final int NUM = 4;
	//private static final int LINE = 10;
	private static final int WIDTH = 110;
	private static final int HEIGHT = 30;
	/**
	 * 画图 
	 * @return
	 */
	public static Map<String,BufferedImage> dynaImage(){
		Map<String,BufferedImage> m = new HashMap<String, BufferedImage>();
		BufferedImage image = new BufferedImage(WIDTH,HEIGHT,BufferedImage.TYPE_INT_RGB);
		Graphics grap = image.getGraphics();
		grap.setColor(new Color(150,150,150));
		grap.fillRect(0, 0, WIDTH, HEIGHT);
		String ranString = RandomUtil.randomCandidate(NUM);
		for(int i=0;i<NUM;i++){
			grap.setColor(getRandomColor());
			grap.setFont(new Font(null,Font.BOLD,20));
			grap.drawString(String.valueOf(ranString.toCharArray()[i]), 10+i*WIDTH/NUM, HEIGHT/2+5);
		}
		for(int i=0;i<NUM;i++){
			Random ran = new Random();
			grap.setColor(getRandomColor());
			grap.drawLine(ran.nextInt(WIDTH), ran.nextInt(HEIGHT), ran.nextInt(WIDTH), ran.nextInt(HEIGHT));
			
		}
		m.put(ranString, image);
		return m;
	}
	
	private static Color getRandomColor(){
		Random ran = new Random();
		return new Color(ran.nextInt(128),ran.nextInt(128),ran.nextInt(128));
	}
}
